<?php
$CI =& get_instance();
$CI->load->library('pagination');
$CI->load->model('Model_store', 'model_store');
$CI->load->model('Model_type', 'model_type');
parse_str($_SERVER['QUERY_STRING'],$_GET);  
$_keyword = $CI->input->get("keyword");
$_types = $CI->input->get("types");
// Set to cookie
if(!empty($_keyword)){
	$CI->session->set_userdata('keyword', $_keyword);
}
//var_dump($_GET);

$limit = 10;
$total = $CI->model_store->browse_count($_keyword, $_types, null);
$offset = 0;
$per_page = $CI->uri->segment(4,0);
if($per_page < $total){
	$offset = $per_page;
}
$stores = $CI->model_store->browse($_keyword, $_types);
$config['base_url'] = site_url(array('c'=>'home', 'm'=>'search'));
$config['uri_segment'] = 4;
$config['total_rows'] = $total;
$config['per_page'] = $limit;
$CI->pagination->initialize($config); 

// Fetch All User Type
$types = $CI->model_type->fetchAll();
?>
<div class="left-col">
	<?php if(is_array($stores)):?>
	<h3 style="padding-bottom: 7px;"> We've found <span style='color: #FF0000;'> <?=$CI->pagination->total_rows;?> Nail Salons </span> near your location <span style='color: #FF0000;'>( <?= $_keyword?> ) </span></h3>
	<table width="700" cellpadding="0" cellspacing="1">	
		<thead>
			<tr>
				<th width="168"><?=lang('photo');?></th>
				<th><?=lang('address');?></th>
				<th>Info.</th>
			</tr>
		</thead>
		<tbody>
		<?php $i = 0;foreach($stores as $item):$i++;?>
			<tr>
			<td>
				<a href="<?=site_url(array('c' => 'home', 'm' => 'store_detail', 'nav'=> 1, 'id' => $item['id']))?>">
					<img width= "200" height="120" src="<?=$item['image']?>" alt="<?=$item['company_name']?>"/>
				</a>
			</td>
			<td>
				<p><h2 style="padding-bottom: 7px;"><?=$item['company_name']?></h2></p>
				<p><h5><?=$item['address']?></h5></p>
				<p><h5 style="padding-bottom: 7px;"><?=$item['city']?>, <?=$item['state']?> <?=$item['zipcode']?></h5></p>
				<p><span class="phone"><?=$item['home_phone']?></span></p>
				<?php if(!empty($item['website'])):?>
				<p class="website"><label><?=lang('website');?></label> : <a href="<?=$item['website']?>" title="Website"><?=$item['website']?></a></p>
				<?php endif;?>
				<p>>   <a href="#" class="viewmap" title="View Map" rel="#map<?=$i;?>">view map</a></p>
			</td>
            <td> <p> Business Hours:</p>
                <p><?=$item['business_hour']?></p>			
				<a href="<?=site_url(array('c' => 'home', 'm' => 'store_detail', 'nav'=> 1, 'id' => $item['id']))?>">more details...</a></p>
			</td>
			</tr>
		<?php endforeach;?>
	</tbody>
	</table>
	<?php else:?>
	<h2>Nail Salons in your area are not list on our website yet.
	Please ask them to Join Us !</h2>
	<?php endif;?>
	<div class="pagination"><?=$CI->pagination->create_links();?></div>
	<?php if(is_array($stores)):?>
	<?php $i = 0;foreach($stores as $item):$i++;?>
		<div id="map<?=$i?>" class="simple_overlay"><?=$item['google_map']?></div>
	<?php endforeach;?>
	<?php endif;?>
</div>
<div class="right-col">
	<h2>Filter your result</h2>
	<div class="right-col-inner">
		<form action="<?=site_url(array('c'=>'home','m'=>'search'))?>" method="get" name="search_form">
		<input type="hidden" name="keyword" value="<?=$_keyword;?>"/>
		<?php if(is_array($types)):?>
		<ul>
		<?php foreach($types as $item):?>
			<?php 
			$_checked = "";
			if(!empty($_types) && array_search($item['id'], $_types) !== FALSE){
				$_checked = "checked='true'";
			}
			?>
			<li><input type="checkbox" name="types[]" <?=$_checked?> value="<?=$item['id']?>"/><label><?=$item['title']?></label></li>		<?php endforeach;?>
		</ul>
		<?php endif;?>
		<div align="center">
			<input class="filter-btn" type="submit" name="submit" value="Update Search"/>
		</div>
		</form>
	</div>
</div>
<div class="clearfix"></div>
<script type="text/javascript">
$(function(){
	$(".viewmap").overlay({mask: {
		color: '#ebecff',
		loadSpeed: 200,
		opacity: 0.9
	}});
});
</script>